import qs from "qs";
import dayjs from "dayjs";
import { getUrlParams } from "@/app/cg06/api/baseInfo";
import { fetchWrapper } from "@/app/cg06/api/common2";

const pathMap = {
  development: '/uat-api',
  dev: '/dev-api',
  staging: '/uat-api',
  prod: '/prod-api',
};
const env = (process.env.NEXT_PUBLIC_APP_ENV || 'prod') as
  | 'dev'
  | 'staging'
  | 'prod';

const envTest =
  typeof window !== 'undefined' &&
  (new URL(window.location.href).searchParams.get('env') as typeof env);

console.log(envTest, 'envTest');
const envFinale = env == 'prod' ? env : envTest || env;
const path = pathMap[envFinale];

const wmsPath = path;
const reportPath = path + "-report";

const preDay = dayjs().subtract(1, "day").format("YYYY-MM-DD");
// mock版本
const gylMockVersion = getUrlParams("mockVersion") || "";
// 没有配置查询时间默认为前一天
const gylSearchDay = getUrlParams("searchDay") || preDay;

/**仓库地图报表信息 */
export function statisticsOrderChartApi() {
  return fetchWrapper<any>(
    `${reportPath}/report/large-screen/gyl-statisticsChart`,
    {
      gylMockVersion,
      gylSearchDay,
      warehouseIds: ["102743510335520"],
      tenantId: "1000000004",
    },
    "POST"
  );
}

/**仓库地图信息 */
export function globalInfoApi() {
  const params = qs.stringify({
    mockVersion: gylMockVersion,
    date: gylSearchDay,
    warehouseIds: ["102743510335520"],
    tenantId: "1000000004",
  });
  return fetchWrapper<any>(
    `${wmsPath}/wms/warehouse/banner-warehouse-v3?${params}`,
    undefined,
    "GET"
  );
}
